<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入客户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"><el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['buss:sqzxt:add']">新增</el-button></el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['buss:sqzxt:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5"><el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['buss:sqzxt:export']">导出</el-button></el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-form ref="elForm" size="small" :disabled="true" label-width="120px">
      <el-row type="flex" justify="start" align="top">
        <el-form-item label="社区数量" prop="sssqs"><el-input v-model="dataWgWgsqSq.sssqs" placeholder="" clearable :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="总户数" prop="hs"><el-input v-model="dataWgWgsqSq.hs" :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="存款户数" prop="ckhs"><el-input v-model="dataWgWgsqSq.ckhs" clearable :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="存款金额" prop="ckye"><el-input v-model="dataWgWgsqSq.ckye" :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="贷款户数" prop="field126"><el-input v-model="dataWgWgsqSq.dkhs" :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="贷款余额" prop="field126"><el-input v-model="dataWgWgsqSq.dkye" :style="{ width: '100%' }"></el-input></el-form-item>
      </el-row>
      <el-row type="flex" justify="start" align="top">
        <el-form-item label="电银产品数" prop="field124"><el-input v-model="dataWgWgsqSq.dzyhgs" clearable :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="家庭产品覆盖面" prop="field123"><el-input v-model="dataWgWgsqSq.productCoverage" :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="有效家庭覆盖面" prop="field125"><el-input v-model="dataWgWgsqSq.familyCoverage" clearable :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="授信金额" prop="field126"><el-input v-model="dataWgWgsqSq.sxje" :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="授信签约率" prop="field126"><el-input v-model="dataWgWgsqSq.sxqyl" :style="{ width: '100%' }"></el-input></el-form-item>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="sqzxtList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="户主" align="center" prop="hzxm" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="户籍编号" width="180" align="center" prop="hjbh" />
      <el-table-column label="姓名" width="120" align="center" prop="name" />
      <el-table-column label="证件号码" width="180" align="center" prop="idCard" />
      <el-table-column label="联系电话" width="120" align="center" prop="phone" />
      <el-table-column label="性别" align="center" prop="sex" :formatter="sexFormat"/>
      <el-table-column label="与户主关系" width="120" align="center" prop="yhzgx" :formatter="yhzgxFormat" />
      <el-table-column label="所属社区" align="center" prop="sssq" />
      <el-table-column label="长期居住" align="center" prop="longLive" />
      <el-table-column label="地址" width="200" align="center" prop="address" />
      <el-table-column label="家庭人口" align="center" prop="labour" />
      <el-table-column label="客户星级" align="center" prop="level" :formatter="khxjFormat" />
      <el-table-column label="贫困户" width="120" align="center" prop="pkh" :formatter="pkhTypeFormat" />
      <el-table-column label="黑名单" align="center" prop="black" :formatter="blackTypeFormat" />
      <el-table-column label="管户机构" width="120" align="center" prop="orgName"/>
      <el-table-column label="管户经理" width="120" align="center" prop="managerName" />

      <el-table-column label="操作" fixed="right" width="220" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link :to="{ path: '/sq/sqdetail/', query: { sqBG: scope.row } }" class="link-type"><span>客户视图  </span></router-link>
          <router-link :to="{ path: '/sq/sqbg/', query: { sqBG: scope.row } }" class="link-type"><span>变更记录</span></router-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改网格社区按社区维度统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="dataWgWgsqSq" :model="dataWgWgsqSq" :rules="rules" label-width="120px">

        <el-col :span="24">
          <div style="margin: 1.5625rem;font-size: 14px;">
            <el-collapse v-model="activeNamesk">
              <el-collapse-item title="存量客户" name="1">
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="姓名" prop="name"><el-input v-model="dataWgWgsqSq.name" @input="onInput()" placeholder="请输入姓名" clearable :style="{ width: '100%' }"></el-input></el-form-item>
                      </div>
                    </el-col>
                </div>
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="身份证号" prop="idCard">
                          <el-input v-model="dataWgWgsqSq.idCard" @input="onInput()" placeholder="请输入身份证" clearable :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                      </div>
                    </el-col>
                </div>
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="户主姓名" prop="hzxm">
                          <el-input v-model="dataWgWgsqSq.hzxm" @input="onInput()" placeholder="请输入户主姓名" clearable :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                      </div>
                    </el-col>
                </div>
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="户籍编号" prop="hjbh">
                          <el-input v-model="dataWgWgsqSq.hjbh" @input="onInput()" placeholder="请输入户籍编号" clearable :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                      </div>
                    </el-col>
                </div>
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="年龄" prop="age"><el-input v-model="dataWgWgsqSq.age" @input="onInput()" placeholder="请输入年龄" clearable :style="{ width: '100%' }"></el-input></el-form-item>
                      </div>
                    </el-col>
                </div>
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="手机号" prop="phone">
                          <el-input v-model="dataWgWgsqSq.phone" placeholder="请输入手机号" @input="onInput()" clearable :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                      </div>
                    </el-col>

                </div>
                <div>
                    <el-col :span="12">
                      <div style="margin: 1.5625rem;font-size: 14px;">
                        <el-form-item label="客户类型" prop="khlx">
                          <el-select v-model="khlxvalue" placeholder="请选择">
                              <el-option
                                v-for="item in khlx"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                              </el-option>
                            </el-select>
                        </el-form-item>
                      </div>
                    </el-col>
                </div>
                 <div>
                   <el-col :span="12">
                     <div style="margin: 1.5625rem;font-size: 14px;">
                       <el-form-item label="客群标签" prop="groupLabel">
                         <el-select v-model="qtbqvalue" @change="selectWorkName" multiple placeholder="请选择">
                             <el-option
                               v-for="item in groupList"
                               :key="item.value"
                               :label="item.groupName"
                               :value="`${item.groupName}|${item.groupCode}`">
                             </el-option>
                           </el-select>
                       </el-form-item>
                     </div>
                   </el-col>
                 </div>
              </el-collapse-item>

            </el-collapse>
          </div>
        </el-col>

        <el-col :span="24">
          <div style="margin: 1.5625rem;font-size: 14px;">
            <el-collapse v-model="activeNamesss">
              <el-collapse-item title="网格社区" name="2">
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="家庭人口" prop="labour">
                        <el-input v-model="dataWgWgsqSq.labour" @input="onInput()" placeholder="请输入家庭人口" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="地址" prop="address">
                        <el-input v-model="dataWgWgsqSq.address" @input="onInput()" placeholder="请输入地址" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="活动次数" prop="joinAcive">
                        <el-input v-model="dataWgWgsqSq.joinAcive" @input="onInput()" placeholder="请输入活动参与次数" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="所属社区" prop="sssjsq">
                        <el-select v-model="dataWgWgsqSq.sssjsq" @change="sssqBlur(dataWgWgsqSq.sssjsq)" clearable placeholder="请选择"><el-option v-for="item in sssjsqList" :key="item.value" :label="item.sssjsq" :value="item.sssjsq"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="长期居住" prop="longLive">
                        <el-select v-model="cqjzvalue" clearable placeholder="请选择"><el-option v-for="item in cqjz" :key="item.value" :label="item.label" :value="item.value"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="所属小区" prop="sssq">
                        <el-select v-model="dataWgWgsqSq.sssq" clearable placeholder="请选择"><el-option v-for="item in xsqList" :key="item.value" :label="item.sssq" :value="item.sssq"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="管户机构" prop="orgId">
                        <el-select v-model="orgvalue" @change="orgIdBlur(orgvalue)" clearable placeholder="请选择"><el-option v-for="item in orgList" :key="item.value" :label="item.orgName" :value="item.orgId"></el-option></el-select>
                      </el-input></el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="管户经理" prop="managerId">
                        <el-select v-model="managervalue" clearable placeholder="请选择"><el-option v-for="item in mangerList" :key="item.value" :label="item.nickName" :value="item.userId"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="与户主关系" prop="yhzgx">
                        <el-select v-model="yhzgxvalue" clearable placeholder="请选择"><el-option v-for="item in yhzgx" :key="item.value" :label="item.label" :value="item.value"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>

                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="备注" prop="remark">
                        <el-input v-model="dataWgWgsqSq.remark" @input="onInput()" placeholder="请输入备注" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
              </el-collapse-item>
            </el-collapse>
          </div>
        </el-col>



        <el-col :span="24">
          <div style="margin: 1.5625rem;font-size: 14px;">
            <el-collapse v-model="activeNames" >
              <el-collapse-item title="网格商户" name="3">
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="商户门头" prop="shmt">
                        <el-input v-model="dataWgWgsqSq.shmt" @input="onInput()" placeholder="请输入商户门头" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="注册名称" prop="shzcmc">
                        <el-input v-model="dataWgWgsqSq.shzcmc" @input="onInput()" placeholder="请输入注册名称" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="法定代表人" prop="fddbr">
                        <el-input v-model="dataWgWgsqSq.fddbr" @input="onInput()" placeholder="请输入法定代表人" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="代表人证件" prop="fddbrzjhm">
                        <el-input v-model="dataWgWgsqSq.fddbrzjhm" @input="onInput()" placeholder="请输入代表人证件" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="实际经营人" prop="sjjyr">
                        <el-input v-model="dataWgWgsqSq.sjjyr" @input="onInput()" placeholder="请输入实际经营人" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="经营人证件" prop="sjjyrzjhm">
                        <el-input v-model="dataWgWgsqSq.sjjyrzjhm" @input="onInput()" placeholder="请输入经营人证件" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="经营地址" prop="jydz">
                        <el-input v-model="dataWgWgsqSq.jydz" @input="onInput()" placeholder="请输入经营地址" clearable :style="{ width: '100%' }"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="所属行业" prop="sshy">
                        <el-select v-model="dataWgWgsqSq.sshy" clearable placeholder="请选择"><el-option v-for="item in sshy" :key="item.value" :label="item.label" :value="item.value"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">
                      <el-form-item label="经营状况" prop="jyzk">
                        <el-select v-model="dataWgWgsqSq.jyzk" clearable placeholder="请选择"><el-option v-for="item in jyzk" :key="item.value" :label="item.label" :value="item.value"></el-option></el-select>
                      </el-form-item>
                    </div>
                  </el-col>
                </div>
                <div>
                  <el-col :span="12">
                    <div style="margin: 1.5625rem;font-size: 14px;">

                    </div>
                  </el-col>
                </div>
              </el-collapse-item>
            </el-collapse>
          </div>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSqzxt, getSqzxt, delSqzxt, addSqzxt, updateSqzxt, selectSssqList, orglist, queryManager, addWgsq, listGroup } from '@/api/buss/sqzxt';
import { addCustomer, updateCustomer, queryCustomerInfo} from '@/api/buss/customer';
import { jquery } from '@/utils/jquery-1.8.3.min';

export default {
  name: 'Sqcustuer',
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 网格社区按社区维度统计表格数据
      sqzxtList: [],
      activeNames: ['1'],
      activeNamesss: ['1'],
      activeNamesk: ['1'],
      sexOptions: [],
      dataWgWgsqSq: {
        name: '',
        idCard: '',
        hzxm: '',
        hjbh: '',
        age: '',
        phone: '',
        labour: '',
        address: '',
        joinAcive: '',
        sssq: '',
        longLive: '',
        yhzgx: '',
        orgId: '',
        managerId: '',
        remark: '',
        sssjsq: '',
        khlx: '',
        groupLabel: '',
        sshy: '',
        jyzk: '',
        jydz: '',
        sjjyrzjhm: '',
        sjjyr: '',
        fddbrzjhm: '',
        fddbr: '',
        shzcmc: '',
        shmt: ''
      },
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      cqjz: [
        {
          value: '0',
          label: '是'
        },
        {
          value: '1',
          label: '否'
        }
      ],
      cqjzvalue: '',
      khlx: [
        {
          value: '0',
          label: '普通客户'
        },
        {
          value: '1',
          label: '潜在客户'
        },
        {
          value: '2',
          label: '重点客户'
        }
      ],
      khlxvalue: '',
      jyzk: [
        {
          value: '0',
          label: '关闭'
        },
        {
          value: '1',
          label: '正常'
        },
        {
          value: '2',
          label: '其他'
        }
      ],
      jyzkvalue: '',
      yhzgx: [
        {
          value: '1',
          label: '户主'
        },
        {
          value: '2',
          label: '配偶'
        },
        {
          value: '3',
          label: '父母'
        },
        {
          value: '4',
          label: '子女'
        },
        {
          value: '5',
          label: '其他'
        }
      ],
      yhzgxvalue: '',
      sshy: [
        {
          value: '1',
          label: '餐饮'
        },
        {
          value: '2',
          label: '住宿'
        },
        {
          value: '3',
          label: '商超零售'
        },
        {
          value: '4',
          label: '水产批发'
        },
        {
          value: '5',
          label: '汽车服务'
        },
        {
          value: '6',
          label: '居民服务'
        },
        {
          value: '7',
          label: '其他'
        }
      ],
      sshyvalue: '',
      orgvalue: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        sssq: null,
        hs: null,
        ckhs: null,
        ckye: null,
        dkhs: null,
        dkye: null,
        etchs: null,
        xykhs: null,
        sjwxhs: null,
        sbkhs: null,
        yxdkrs: null,
        rs: null,
        dzyhgs: null,
        productFamilyHs: null,
        productCoverage: null,
        vaildFamilyHs: null,
        familyCoverage: null,
        orgId: null,
        managerId: null,
        rzlcoount: null,
        familyfgm: null,
        rzl: null,
        xzjmzb: null,
        gtgshzb: null,
        gzryzb: null,
        sjrq: null,
        amountYsh: null,
        ifysx: null,
        qyZjhm: null,
        sxje: null,
        familyQyCoverage: null,
        sfyxdkAll: null
      },
      // 表单参数
      form: {

      },
      // 表单校验
      rules: {
        name: [
               { required: true, message: '姓名不能为空', trigger: 'blur' },
                 { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
               ],
        sshy: [
           {required: true, message: "所属行业不能为空" ,trigger: 'blur'},
        ],
        shmt: [
           {required: true, message: "商户门头不能为空" ,trigger: 'blur'},
        ],
        jyzk: [
           {required: true, message: "经营状况不能为空" ,trigger: 'blur'},
        ],
        sssjsq: [
           {required: true, message: "所属小区不能为空" ,trigger: 'blur'},
        ],
        sssq: [
           {required: true, message: "所属社区不能为空" ,trigger: 'blur'},
        ],
      },
      sssq: '',
      orgList: [],
      sqKhxx: [],
      sqtype: {
        type: '1'
      },
      xqtype: {
        type: '2',
        sssjsq: ''
      },
      // 机构ID字典
      orgIdOptions: [],
      sssjsqList: [],
      sssjsqvalue: '',
      xsqList: [],
      xqvalue: '',
      manger: {
        orgId: ''
      },
      mangerList: [],
      managervalue: '',
      qtbqvalue: '',
      groupList: [],
      ifUpAndAdd: false,
      upDateId: '',
      queryInfo: {},
      wgsqyhzgxOptions: [],
      pkhbusstypeOptions: [],
      blacktypeOptions: [],
      khxjOptions: []
    };
  },
  created() {
    const sssp = this.$route.query.sqZ;
    this.sssq = sssp;
    this.getList();
    this.getDicts("sys_org_id").then(response => {
      this.orgIdOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("wgcj_yhzgx").then(response => {
      this.wgsqyhzgxOptions = response.data;
    });
    this.getDicts("sys_buss_type").then(response => {
      this.pkhbusstypeOptions = response.data;
    });
    this.getDicts("sys_buss_type").then(response => {
      this.blacktypeOptions = response.data;
    });
    this.getDicts("sys_khxj").then(response => {
      this.khxjOptions = response.data;
    });
  },
  methods: {
    /** 查询网格社区按社区维度统计列表 */
    getList() {
      //const sssp = this.$route.query.sssq;

      this.loading = true;
      this.queryParams.sssq = this.sssq;
      getSqzxt(this.queryParams).then(response => {
        this.sqzxtList = response.data.doList.rows;
        this.dataWgWgsqSq = response.data.dataWgWgsqSq;
        this.total = response.data.doList.total;
        this.loading = false;
      });
      //下拉社区
      selectSssqList(this.sqtype).then(response => {
        this.sssjsqList = response;
        //console.log(JSON.stringify(this.sssjsqList))
      });
      //下拉机构
      orglist().then(response => {
        this.orgList = response.rows;
      });
      //客群标签
      listGroup().then(response => {
         this.groupList = response.rows;
      });
    },
    onInput() {
      this.$forceUpdate();
    },
    // 客户星级字典翻译
    khxjFormat(row, column) {
      return this.selectDictLabel(this.khxjOptions, row.level);
    },
    // 业务是否类型字典翻译
    pkhTypeFormat(row, column) {
      return this.selectDictLabel(this.pkhbusstypeOptions, row.pkh);
    },
    blackTypeFormat(row, column) {
      return this.selectDictLabel(this.blacktypeOptions, row.black);
    },
    // 与户主关系字典翻译
    yhzgxFormat(row, column) {
      return this.selectDictLabel(this.wgsqyhzgxOptions, row.yhzgx);
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    selectWorkName(id){
      var sp = JSON.stringify(this.qtbqvalue);
      let [lable,vaue] = sp.split('|')
        console.log(vaue)
        console.log("select中对应value值",JSON.stringify(this.qtbqvalue))
    },
    //客户经理
    orgIdBlur(mg) {
      this.manger.orgId = mg;
      queryManager(this.manger).then(response => {
        this.mangerList = response.rows;
      });
    },
    sssqBlur(sssjsqvalue) {
      //下拉小区
      this.xqtype.sssjsq = sssjsqvalue
      selectSssqList(this.xqtype).then(response => {
        this.xsqList = response;
        //console.log(JSON.stringify(this.sssjsqList))
      });
      console.log(sssjsqvalue)
    },
    //社区跳转
    SQJump(sssq) {
      //const tableId = row.idCard;
      this.$router.push('/sq/sqcu/' + sssq);
      console.log(4445);
    },
    orgIdFormat(row, column) {
      console.log(JSON.stringify(row.orgId))
      return this.selectDictLabel(this.orgIdOptions, row.orgId);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sssq: null,
        hs: null,
        ckhs: null,
        ckye: null,
        dkhs: null,
        dkye: null,
        etchs: null,
        xykhs: null,
        sjwxhs: null,
        sbkhs: null,
        yxdkrs: null,
        rs: null,
        dzyhgs: null,
        productFamilyHs: null,
        productCoverage: null,
        vaildFamilyHs: null,
        familyCoverage: null,
        orgId: null,
        managerId: null,
        rzlcoount: null,
        familyfgm: null,
        rzl: null,
        xzjmzb: null,
        gtgshzb: null,
        gzryzb: null,
        sjrq: null,
        amountYsh: null,
        ifysx: null,
        qyZjhm: null,
        sxje: null,
        familyQyCoverage: null,
        sfyxdkAll: null
      };
      this.resetForm('form');
    },
    // 性别字典翻译
    // sexFormat(row, column) {
    //   return this.selectDictLabel(this.sexOptions, row.sex);
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;

      this.sqKhxx = selection;



      //console.log(JSON.stringify(this.dataWgWgsqSq.name))
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.sqKhxx = [];
      this.reset();
      this.open = true;
      this.title = '添加网格社区按社区维度统计';
    },
    //客户视图
    handleDetailUpdate(row) {
      const tableId = row.idCard;
      this.$router.push('/buss/detailTable/' + tableId);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      //console.log(JSON.stringify(row))
      //this.reset();
      queryCustomerInfo(this.sqKhxx[0].idCard).then(response => {
        this.queryInfo = response.data;
        this.rules = {};
        console.log(JSON.stringify(this.queryInfo.dataWgWgsq.length))
        this.upDateId = this.queryInfo.id;
        if(this.queryInfo.dataWgWgsq.length > 0){
          this.dataWgWgsqSq.labour = this.queryInfo.dataWgWgsq[0].labour;
          this.dataWgWgsqSq.sssq = this.queryInfo.dataWgWgsq[0].sssq;
          this.dataWgWgsqSq.sssjsq = this.queryInfo.dataWgWgsq[0].sssjsq;
          this.cqjzvalue = this.queryInfo.dataWgWgsq[0].longLive;
        }
        if(this.queryInfo.dataGtgsh.length > 0){
          this.dataWgWgsqSq.shmt = this.queryInfo.dataGtgsh[0].shmt;
          this.dataWgWgsqSq.shzcmc = this.queryInfo.dataGtgsh[0].shzcmc;
          this.dataWgWgsqSq.fddbr = this.queryInfo.dataGtgsh[0].fddbr;
          this.dataWgWgsqSq.fddbrzjhm = this.queryInfo.dataGtgsh[0].fddbrzjhm;
          this.dataWgWgsqSq.sjjyr = this.queryInfo.dataGtgsh[0].sjjyr;
          this.dataWgWgsqSq.sjjyrzjhm = this.queryInfo.dataGtgsh[0].sjjyrzjhm;
          this.dataWgWgsqSq.jydz = this.queryInfo.dataGtgsh[0].jydz;
          this.dataWgWgsqSq.sshy = this.queryInfo.dataGtgsh[0].sshy;
          this.dataWgWgsqSq.jyzk = this.queryInfo.dataGtgsh[0].jyzk;
        }
      });
      this.dataWgWgsqSq.name = this.sqKhxx[0].name;
      this.dataWgWgsqSq.idCard = this.sqKhxx[0].idCard;
      this.dataWgWgsqSq.hzxm = this.sqKhxx[0].hzxm;
      this.dataWgWgsqSq.hjbh = this.sqKhxx[0].hjbh;
      this.dataWgWgsqSq.age = this.queryInfo.age;
      this.dataWgWgsqSq.phone = this.queryInfo.phone;


      this.dataWgWgsqSq.address = this.queryInfo.address;
      this.dataWgWgsqSq.joinAcive = this.sqKhxx[0].joinAcive;


      this.yhzgxvalue = this.sqKhxx[0].yhzgx;
      this.orgvalue = this.queryInfo.orgId;
      this.managervalue = this.queryInfo.userId;
      this.khlxvalue = this.queryInfo.customerType;
      this.dataWgWgsqSq.remark = this.sqKhxx[0].remark;

      this.open = true;
      this.title = '修改网格社区按社区维度统计';
      this.ifUpAndAdd = row.isTrusted;


      // const id = row.id || this.ids;

    },
    selectGet(vId){
          console.log(vId);
          let obj = {};
          obj = this.groupList.find((item)=>{
              return item.id === vId;
          });
          console.log(obj.groupCode);
          console.log(obj.groupName);
    },
    /** 提交按钮 */
    submitForm() {

      this.$refs['dataWgWgsqSq'].validate(valid => {
        if (valid) {
          console.log(this.form.id)
          if (this.ifUpAndAdd) {

            this.rules = "";

            console.log("修改")
            var group = [];
            for (var i = 0; i < this.qtbqvalue.length; i++) {

                  group.push({
                       groupCode: this.qtbqvalue[i].split('|')[1],
                       groupName: this.qtbqvalue[i].split('|')[0]
                  })
            }
            var sqData = {
              name: this.dataWgWgsqSq.name,
              idCard: this.dataWgWgsqSq.idCard,
              hzxm: this.dataWgWgsqSq.hzxm,
              hjbh: this.dataWgWgsqSq.hjbh,
              age: this.dataWgWgsqSq.age,
              phone: this.dataWgWgsqSq.phone,
              groupLabel: group,
              customerType: this.khlxvalue,
              id: this.upDateId,
              dataGtgsh: [{}],
              dataWgWgsq: [{}]

            }

            if(this.queryInfo.dataWgWgsq.length > 0){
              sqData.dataWgWgsq[0].id = this.queryInfo.dataWgWgsq[0].id;
              sqData.dataWgWgsq[0].yhzgx = this.yhzgxvalue;
              sqData.dataWgWgsq[0].remark = this.dataWgWgsqSq.remark;
              sqData.dataWgWgsq[0].managerId = this.managervalue;
              sqData.dataWgWgsq[0].orgId = this.orgvalue;
              sqData.dataWgWgsq[0].sssq = this.dataWgWgsqSq.sssq;
              sqData.dataWgWgsq[0].labour = this.dataWgWgsqSq.labour;
              sqData.dataWgWgsq[0].address = this.dataWgWgsqSq.address;
              sqData.dataWgWgsq[0].joinAcive = this.dataWgWgsqSq.joinAcive;
              sqData.dataWgWgsq[0].sssjsq = this.dataWgWgsqSq.sssjsq;
              sqData.dataWgWgsq[0].longLive = this.cqjzvalue;
            }else{
              sqData.dataWgWgsq = [];
            }

            if(this.queryInfo.dataGtgsh.length > 0){
              sqData.dataGtgsh[0].shmt = this.dataWgWgsqSq.shmt;
              sqData.dataGtgsh[0].shzcmc = this.dataWgWgsqSq.shzcmc;
              sqData.dataGtgsh[0].fddbr = this.dataWgWgsqSq.fddbr;
              sqData.dataGtgsh[0].fddbrzjhm = this.dataWgWgsqSq.fddbrzjhm;
              sqData.dataGtgsh[0].sjjyr = this.dataWgWgsqSq.sjjyr;
              sqData.dataGtgsh[0].sjjyrzjhm = this.dataWgWgsqSq.sjjyrzjhm;
              sqData.dataGtgsh[0].jydz = this.dataWgWgsqSq.jydz;
              sqData.dataGtgsh[0].sshy = this.dataWgWgsqSq.sshy;
              sqData.dataGtgsh[0].jyzk = this.dataWgWgsqSq.jyzk;
              sqData.dataGtgsh[0].id = this.queryInfo.dataGtgsh[0].id;
              sqData.dataGtgsh[0].sssq = this.dataWgWgsqSq.sssq;
              sqData.dataGtgsh[0].sssjsq = this.dataWgWgsqSq.sssjsq;
            }else{
              sqData.dataGtgsh = [];
            }


            // if(this.sssjsqvalue!=null){
            //   sqData.dataGtgsh[0].sssjsq = this.sssjsqvalue;
            // }
            // if(this.xqvalue!=null){
            //   sqData.dataGtgsh[0].sssq = this.xqvalue;
            // }
            this.ifUpAndAdd = true;
            console.log(sqData)
            updateCustomer(sqData).then(response => {
              this.msgSuccess('修改成功');
              this.open = false;
              this.getList();
            });

          } else {
            var group = [];
            for (var i = 0; i < this.qtbqvalue.length; i++) {

                  group.push({
                       groupCode: this.qtbqvalue[i].split('|')[1],
                       groupName: this.qtbqvalue[i].split('|')[0]
                  })
            }
            var sqData = {
              name: this.dataWgWgsqSq.name,
              idCard: this.dataWgWgsqSq.idCard,
              hzxm: this.dataWgWgsqSq.hzxm,
              hjbh: this.dataWgWgsqSq.hjbh,
              age: this.dataWgWgsqSq.age,
              phone: this.dataWgWgsqSq.phone,
              labour: this.dataWgWgsqSq.labour,
              address: this.dataWgWgsqSq.address,
              joinAcive: this.dataWgWgsqSq.joinAcive,
              sssq: this.xqvalue,
              longLive: this.dataWgWgsqSq.longLive,
              yhzgx: this.yhzgxvalue,
              orgId: this.orgvalue,
              managerId: this.managervalue,
              remark: this.dataWgWgsqSq.remark,
              sssjsq: this.sssjsqvalue,
              groupLabel: group,
              customerType: this.khlxvalue,
              dataGtgsh: [{}],
              dataWgWgsq: [{}]

            }

            if(this.yhzgxvalue!=""){
              sqData.dataWgWgsq[0].yhzgx = this.yhzgxvalue;
            }
            if(this.dataWgWgsqSq.remark!=""){
              sqData.dataWgWgsq[0].remark = this.dataWgWgsqSq.remark;
            }
            if(this.managervalue!=""){
              sqData.dataWgWgsq[0].managerId = this.managervalue;
            }
            if(this.orgvalue!=""){
              sqData.dataWgWgsq[0].orgId = this.orgvalue;
            }
            if(this.dataWgWgsqSq.sssq!=""){
              sqData.dataWgWgsq[0].sssq = this.dataWgWgsqSq.sssq;
            }
            if(this.dataWgWgsqSq.labour!=""){
              sqData.dataWgWgsq[0].labour = this.dataWgWgsqSq.labour;
            }
            if(this.dataWgWgsqSq.address!=""){
              sqData.dataWgWgsq[0].address = this.dataWgWgsqSq.address;
            }
            if(this.dataWgWgsqSq.joinAcive!=""){
              sqData.dataWgWgsq[0].joinAcive = this.dataWgWgsqSq.joinAcive;
            }
            if(this.dataWgWgsqSq.sssjsq!=""){
              sqData.dataWgWgsq[0].sssjsq = this.dataWgWgsqSq.sssjsq;
            }else{
              sqData.dataWgWgsq = []
            }
            if(this.cqjzvalue!=""){
              sqData.dataWgWgsq[0].longLive = this.cqjzvalue;
            }

            if(this.dataWgWgsqSq.shmt!=""){
              sqData.dataGtgsh[0].shmt = this.dataWgWgsqSq.shmt;
            }
            if(this.dataWgWgsqSq.shzcmc!=""){
              sqData.dataGtgsh[0].shzcmc = this.dataWgWgsqSq.shzcmc;
            }
            if(this.dataWgWgsqSq.fddbr!=""){
              sqData.dataGtgsh[0].fddbr = this.dataWgWgsqSq.fddbr;
            }
            if(this.dataWgWgsqSq.fddbrzjhm!=""){
              sqData.dataGtgsh[0].fddbrzjhm = this.dataWgWgsqSq.fddbrzjhm;
            }
            if(this.dataWgWgsqSq.sjjyr!=""){
              sqData.dataGtgsh[0].sjjyr = this.dataWgWgsqSq.sjjyr;
            }
            if(this.dataWgWgsqSq.sjjyrzjhm!=""){
              sqData.dataGtgsh[0].sjjyrzjhm = this.dataWgWgsqSq.sjjyrzjhm;
            }
            if(this.dataWgWgsqSq.jydz!=""){
              sqData.dataGtgsh[0].jydz = this.dataWgWgsqSq.jydz;
            }
            if(this.dataWgWgsqSq.sshy!=""){
              sqData.dataGtgsh[0].sshy = this.dataWgWgsqSq.sshy;
            }
            if(this.dataWgWgsqSq.jyzk!=""){
              sqData.dataGtgsh[0].jyzk = this.dataWgWgsqSq.jyzk;
            }
            if(this.dataWgWgsqSq.sssjsq!=""){
              sqData.dataGtgsh[0].sssjsq = this.dataWgWgsqSq.sssjsq;
            }
            if(this.dataWgWgsqSq.sssq!=""){
              sqData.dataGtgsh[0].sssq = this.dataWgWgsqSq.sssq;
            }


            // for (var i = 0; i < this.qtbqvalue.length; i++) {
            //   console.log(this.qtbqvalue[i].split('|')[0])
            // }

            //console.log(JSON.stringify(group))
            console.log(sqData)
            addCustomer(sqData).then(response => {
              this.msgSuccess('新增成功');
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除网格社区按社区维度统计编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delSqzxt(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess('删除成功');
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'buss/sqzxt/export',
        {
          ...this.queryParams
        },
        `buss_sqzxt.xlsx`
      );
    }
  }
};
</script>
